//placer.cpp

#include "stdafx.h"
#include "placer.h"
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

void placer::generate()
{
	int p = rand()%100;
	int n1, n2, pl1, r1;
	if(p<20)
	{
		do
			n1 = rand()%nodes.size();
		while(!nodes[n1].move);
		do
		{
			pl1 = rand()%rows[0].num_sites;
			r1 = rand()%rows.size();
		}
		while(pl1);
	}
	else
	{
		do
			n1 = rand()%nodes.size();
		while(!nodes[n1].move);
		do
			n2 = rand()%nodes.size();
		while(!nodes[n2].move && n1==n2);
	}
}

void placer::cost()
{
	cost_prev = cost_total;
	cost1 = cost2 = cost3 = 0;
	for(int i=0; i<nets.size(); i++)
		cost1 += nets[i].cost;
	cost_total = cost1 + cost2 + cost3;
}